
import axios from 'axios';
import e from 'cors';
import { Avatar } from 'element-ui';
import { error } from 'shelljs';
//这是工具类封装类一些功能
export default{
    $request: function (method,url,data) {
// var urls = "http://110.42.188.221:8989"
       return new Promise((resolve,reject)=>{
        var data
        axios({
          method: method,
          url:url,
          data:data
        }).then(response => {
          // console.log(response)
         data =  response;
          // console.log("处理后" + this.UserInfo_url)
            console.log(data)

          resolve(data.data)
        }).catch(error=>{
            reject(error)
        })
        // return data
       })

      },
    //   return  

    $getWindowWidth:function(){//用于获取屏幕宽度
      let width=window.innerWidth;
      return width
    },
    $getWindowHeight:function(){//用于获取屏幕高度
      let height = window.innerHeight;
      return height
    },

    open() {
      this.$confirm('此功能需要登录使用, 是否继续?', '提示', {
        confirmButtonText: '登录',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
       this.$router.replace('/myVolunteer')
        this.$message({
          type: 'success',
          message: '即将前往登录界面!',

        });
      }).catch(() => {
        this.$router.go(-1)
        this.$message({
          type: 'info',
          message: '取消'
        });          
      });
    },
    $getLogin: function () {
      // alert("测试")
      axios({
        method: "GET",
        url: "/userInfo",

      }).then(response => {
        // this.UserInfo = response.data.data;
        console.log(response)
        // alert(response.data.code)
        if(response.data.code==1){
          console.log("已登录")
          // alert("未登录")
          this.open()

        }else{
          // this.open4();
          // alert("未登录")
          this.$message({
          showClose: true,
          message: '用户已登录',
          type: 'success'
        });

        }

      })
    },

}